package com.shwread.android.ui.page.chat.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shwread.android.qysw10000192.R;

import java.util.List;

import logic.bean.AreaBeanModle;

/**
 * Created by lexy on 2016/10/12.
 */

public class AreaAdapterForDB extends BaseAdapter {
    private Context context;
    private List<AreaBeanModle> list;
    private int dataType = -1;

    public AreaAdapterForDB(Context context, List<AreaBeanModle> list, int dataType) {
        this.context = context;
        this.list = list;
        this.dataType = dataType;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mH = null;
        if (convertView == null) {
            mH = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.area_layout, null);
            mH.tVAreaName = (TextView) convertView.findViewById(R.id.tVAreaName);
            convertView.setTag(mH);
        } else {
            mH = (ViewHolder) convertView.getTag();
        }
        if (dataType==1){
            mH.tVAreaName.setText(list.get(position).getProvinceName());
        }else if(dataType==2){
            mH.tVAreaName.setText(list.get(position).getCityName());
        }else if(dataType==3){
            mH.tVAreaName.setText(list.get(position).getAreaName());
        }else if(dataType==4){
            mH.tVAreaName.setText(list.get(position).getCompanyName());
        }
        return convertView;
    }

    private class ViewHolder {
        public TextView tVAreaName;
    }
}
